Page({
  data: {
    studyCount: '2,358',
    todayMinutes: 45,
    totalScore: 280,
    streak: 7,
    task1Done: false,
    task2Done: false,
    task3Done: false,
    completedTasks: 0
  },

  onLoad() {
    // 暂时注释掉实际数据加载
    // this.loadUserData();
  },

  onShow() {
    // 每次显示页面时更新数据
    // this.loadUserData();
  },

  loadUserData() {
    // 获取今日学习时长
    const now = new Date();
    const todayKey = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
    const todayMinutes = wx.getStorageSync(`studyTime_${todayKey}`) || 0;

    // 获取总积分
    const totalScore = getApp().getTotalScore() || 0;

    // 获取连续打卡天数
    const streak = wx.getStorageSync('streak') || 0;

    // 获取任务完成状态
    const task1Done = wx.getStorageSync(`task1_${todayKey}`) || false;
    const task2Done = wx.getStorageSync(`task2_${todayKey}`) || false;
    const task3Done = wx.getStorageSync(`task3_${todayKey}`) || false;
    const completedTasks = [task1Done, task2Done, task3Done].filter(Boolean).length;

    this.setData({
      todayMinutes,
      totalScore,
      streak,
      task1Done,
      task2Done,
      task3Done,
      completedTasks
    });
  },

  goToWordChallenge() {
    wx.navigateTo({
      url: '/subpkg/pages/word-challenge/word-challenge'
    });
  },

  goToSentencePractice() {
    wx.navigateTo({
      url: '/subpkg/pages/sentence-practice/sentence-practice'
    });
  }
});